package com.demo.mcp.functions;

import org.springframework.ai.tool.annotation.Tool;
import org.springframework.stereotype.Service;

@Service
public class WeatherFunction {

	@Tool(name = "getCityWeather",
			description = "根据城市名称获取天气预报，参数为中文城市名")
	public WeatherInfo getWeather(String city) {
		// 模拟数据版本
		return switch(city) {
			case "北京" -> new WeatherInfo(25, "晴", 45);
			case "上海" -> new WeatherInfo(28, "多云", 65);
			case "广州" -> new WeatherInfo(32, "阵雨", 80);
			default -> new WeatherInfo(0, "未知", 0, "暂不支持该城市");
		};
	}

	public record WeatherInfo(
			double temperature,  // 温度（摄氏度）
			String condition,    // 天气状况
			int humidity,        // 湿度百分比
			String message
	) {
		public WeatherInfo(double temp, String cond, int hum) {
			this(temp, cond, hum, "查询成功");
		}
	}

}